<template lang="html">
  <div>
    <div class="container-body w">
      <!-- 入驻的企业 -->
      <div class="card-container">
        <div class="title">
          <h2>热门企业</h2>
        </div>
        <Row :gutter="16">
          <div v-for="(item,index) in companylist" :key="index" @click="toCompanydetail(item.id)">
            <Col span="6">
            <Card style="width:260px;margin-top:20px">
              <div class="company" style="text-align:center">
                <img class="logo" :src="item.logo ? item.logo : '/static/images/qy_uplogo.png'">
                <h3 class="comname wordcut">{{item.comname}}</h3>
                <div class="comtags wordcut">
                  <template>
                    <span v-for="(tag,indexs) in item.companywelfare" :key="indexs">{{tag}}</span>
                  </template>
                </div>
                <div class="address wordcut">
                  {{item.adress}}
                </div>
              </div>
            </Card>
            </Col>
          </div>
        </Row>
        <div class="more" v-show="showmore">
          <button class="more-btn" @click="getCompanylist">加载更多</button>
        </div>
      </div>
      </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      companylist: [],
      dbase: [],
      page: 1,
      showmore: true
    }
  },
  created: function() {
    var that = this;

    that.$axios.get(that.$http.apiurl('mpinfo')).then(res => {
      that.dbase = res.data.dbase;
    });

     if(that.$route.query.cname){
      that.search_jobdata(that.$route.query.cname);
      that.showmore = false
    }else{
       that.getCompanylist();
    }

  },
  methods: {

    getCompanylist() {
      var that = this;
      console.log(this.page)

      that.$axios.get(that.$http.apiurl('companyallinfo',{page:that.page})).then(res => {
        console.log(res.data)
        if (res.data.length > 0) {
          if (that.companylist.length > 0) {
            var comarr = that.companylist;

            that.companylist = comarr.concat(res.data);
            that.page = this.page + 1;
          } else {
            that.companylist = res.data;
            that.page = this.page + 1;
          }
        } else {}
      });
    },
 // 执行搜索
			search_jobdata(cname) {
				this.$http.aget('seach', {
					op: 'com',
					cname: cname
				}).then(res => {
					console.log(res);
					this.companylist = res;
				})
			},
    toCompanydetail(e){
      this.$router.push({name:'companydetail',query:{cid:e}})
    },
  }
}
</script>

<style lang="scss" scoped>
body {
  background-color: #f1f1f1;
}
.card-container {
    background-color: #fff;
    padding: 10px;
    margin-top: 50px;
    
    .title {
        margin: 10px 0;
    }
}

// 入驻的企业
.container-body {
    padding-bottom: 50px;

    .company {
        margin: 10px;

        .logo {
            width: 80px;
            height: 80px;
        }

        .comname {
            height: 22px;
            margin-top: 13px;
            font-size: 16px;
            color: #333;
        }

        .comtags {
            margin-top: 3px;
            color: #999;
            border-bottom: 1px dashed #E0E0E0;
            padding-bottom: 10px;
            height: 32px;
        }

        .wel {
            margin-top: 3px;
            color: #999;

            span {
                display: inline-block;
                width: 61px;
                height: 26px;
                padding: 0 5px;
                font-size: 12px;
                line-height: 26px;
                color: #999;
                border: 1px solid #F0F0F0;
                border-radius: 3px;
                text-align: center;
            }
        }
        .address {
            margin-top: 10px;
        }
    }

}
</style>
